package com.eastfair.auth.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.auth.dto.OrganizationDTO;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.auth.entity.Organization;
import com.eastfair.auth.enumeration.OrganizationOrgTypeEnum;
import com.eastfair.auth.service.OrganizationService;
import com.eastfair.auth.service.ProjectOrganizationService;
import com.eastfair.auth.service.RbookingOrganizationService;
import com.eastfair.auth.vo.UserAccountVo;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.echo.core.EchoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 资源-场馆内部组织
 *
 * </p>
 *
 * @author ligang
 * @date 2022-05-16
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/rbookOrganization")
@Api(value = "rbookOrganization", tags = "资源-场馆内部组织")
public class RbookingOrganizationController {

    @Autowired
    RbookingOrganizationService rbookingOrganizationService;

    /**
     * 查询场馆方
     *
     * @param organizationDTO 实体
     *                        orgType 节点类型
     *                        resourceId 资源id
     *                        resourceType 资源类型
     * @return
     */
    @ApiOperation(value = "查询场馆方", notes = "查询场馆方")
    @PostMapping("/query")
    public R<Organization> query(@RequestBody @Validated({OrganizationDTO.queryResource.class}) OrganizationDTO organizationDTO) {
        return R.success(rbookingOrganizationService.query(organizationDTO));
    }

    /**
     * 创建场内工作组
     *
     * @param organizationDTO 实体
     *                        projectId 项目id
     *                        orgType 节点类型
     *                        name 节点名称
     *                        parentId 父级节点id
     *                        resourceId 资源id
     *                        resourceType 资源类型
     *                        List<Long> userIds 用户id
     *                        List<Long> roleIds 角色id
     * @return
     */
    @ApiOperation(value = "创建场内工作组", notes = "创建场内工作组")
    @PostMapping("/create")
    public R<Organization> create(@RequestBody @Validated({OrganizationDTO.createResource.class}) OrganizationDTO organizationDTO) {
        return rbookingOrganizationService.create(organizationDTO);
    }


    /**
     * 修改场内工作组
     *
     * @param organizationDTO 实体
     *                        projectId 项目id
     *                        orgId 主键id
     *                        name 节点名称
     *                        resourceId 资源id
     *                        resourceType 资源类型
     *                        List<Long> userIds 用户id
     *                        List<Long> roleIds 角色id
     * @return
     */
    @ApiOperation(value = "修改场内工作组", notes = "修改场内工作组")
    @PostMapping("/upd")
    public R<Organization> upd(@RequestBody OrganizationDTO organizationDTO) {
        return rbookingOrganizationService.upd(organizationDTO);
    }

    /**
     * 删除场馆方
     *
     * @param organizationDTO 实体
     *                        projectId 项目id
     *                        orgId 主键id
     * @return
     */
    @ApiOperation(value = "删除场馆方", notes = "删除场馆方")
    @PostMapping("/del")
    public R del(@RequestBody @Validated({OrganizationDTO.delResource.class}) OrganizationDTO organizationDTO) {
        //删除资源
        rbookingOrganizationService.del(organizationDTO);
        return R.success();
    }

    /**
     * 添加员工
     *
     * @param organizationDTO 实体
     *                        projectId 项目id
     *                        orgId 主键id
     *                        userIds 用户id
     *                        resourceId 资源id
     *                        isAdmin  是否管理员
     * @return
     */
    @ApiOperation(value = "添加员工", notes = "添加员工")
    @PostMapping("/addUser")
    public R<Organization> addUser(@RequestBody @Validated({OrganizationDTO.addUserOfResource.class}) OrganizationDTO organizationDTO) {
        return rbookingOrganizationService.addUser(organizationDTO, organizationDTO.getIsAdmin());
    }


    /**
     * 解散员工
     *
     * @param organizationDTO 实体
     *                        projectId 项目id
     *                        orgId 主键id
     *                        userIds 用户id
     *                        resourceId 资源id
     * @return
     */
    @ApiOperation(value = "解散员工", notes = "解散员工")
    @PostMapping("/breakUser")
    public R<Organization> breakUser(@RequestBody @Validated({OrganizationDTO.breakUserOfResource.class}) OrganizationDTO organizationDTO) {
        return rbookingOrganizationService.breakUser(organizationDTO);
    }


}
